package stark.app.function.ve;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import stark.app.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

/**
 * Author：daizhongbin on 2025/4/16
 * Email：1027154338@qq.com
 * Desc:
 */
public class SpeedDataAdapter extends StkProviderMultiAdapter<Float> {

    private float mSelectValue = -1;

    public SpeedDataAdapter() {
        super();
        addItemProvider(new MyItemProvider());
    }

    public void setSelectValue(float value) {
        if (value != mSelectValue) {
            mSelectValue = value;
            notifyDataSetChanged();
        }
    }

    private class MyItemProvider extends BaseItemProvider<Float> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_speed_data;
        }

        @Override
        public void convert(@NonNull BaseViewHolder holder, Float aFloat) {
            TextView tvSpeed = holder.getView(R.id.tvSpeed);
            tvSpeed.setText(String.format("x%.1f", aFloat.floatValue()));
            tvSpeed.setSelected(aFloat.floatValue() == mSelectValue);
        }
    }
}
